package com.itheima.app.controller;

import com.itheima.app.manager.MakeFriendManager;
import com.itheima.vo.NearUserVo;
import com.itheima.vo.PageBeanVo;
import com.itheima.vo.RecommendUserVo;
import com.itheima.vo.VisitorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Guanxing
 * @date 2021/9/25
 */
@RestController
public class  MakeFriendController {

    @Autowired
    private MakeFriendManager makeFriendManager;

    //今日佳人
    @GetMapping("/tanhua/todayBest")
    public RecommendUserVo todayBest() {
        return makeFriendManager.todayBest();
    }

    //推荐列表
    @GetMapping("/tanhua/recommendation")
    public PageBeanVo findRecommdUserList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        return makeFriendManager.findRecommendUserList(page, pageSize);
    }

    //查询推荐用户详细信息
    @GetMapping("/tanhua/{recommendUserId}/personalInfo")
    public RecommendUserVo findRecommendUserById(
            @PathVariable Long recommendUserId
    ) {
        return makeFriendManager.findRecommendUserById(recommendUserId);
    }

    //查询陌生人问题
    @GetMapping("/tanhua/strangerQuestions")
    public String findQuestionByUserId(
            Long userId
    ) {
        return makeFriendManager.findQuestionByUserId(userId);
    }

    //查询最近访客
    @GetMapping("/movements/visitors")
    public List<VisitorVo> findVisitors() {
        return makeFriendManager.findVisitors();
    }

    //上传位置
    @PostMapping("/baidu/location")
    public void saveOrUpdateUserLocation(@RequestBody Map<String, String> map) {
        Double latitude = Double.valueOf(map.get("latitude"));
        Double longitude = Double.valueOf(map.get("longitude"));
        String addrStr = map.get("addrStr");
        System.out.println(map);
        ;
        makeFriendManager.saveOrUpdateUserLocation(latitude, longitude, addrStr);
    }

    //附近的人
    @GetMapping("/tanhua/search")
    public List<NearUserVo> findNearUserList(String gender, Long distance) {
        return makeFriendManager.findNearUserList(gender, distance);
    }

    //打招呼
    @PostMapping("/tanhua/strangerQuestions")
    public void replyStrangerQuestion(@RequestBody Map map) {
        String questionUserId = map.get("userId").toString();
        String reply = map.get("reply").toString();
        makeFriendManager.replyStrangerQuestion(questionUserId, reply);
    }

    //添加联系人
    @PostMapping("/messages/contacts")
    public void addContacts(@RequestBody Map map) {
        String friendId = map.get("userId").toString();
        makeFriendManager.addContacts(friendId);
    }

    //查询联系人列表
    @GetMapping("/messages/contacts")
    public PageBeanVo findContactList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        return   makeFriendManager.findContactList(page , pageSize);
    }

    //探花查询卡片
    @GetMapping("/tanhua/cards")
    public List<RecommendUserVo> findTanhuaCards(){
        //查询推荐好友的信息
        PageBeanVo pageBeanVo = makeFriendManager.findRecommendUserList(1,10);
        List<RecommendUserVo> items = (List<RecommendUserVo>) pageBeanVo.getItems();

        return items;
    }
}
